let s = '([{}])'

var isValid = function (s) {
  const lToR = {
    '(': ')',
    '[': ']',
    '{': '}'
  }

  const stack = []

  for (let i = 0; i < s.length; i++) {
    if (s[i] === '(' || s[i] === '[' || s[i] === '{') {
      stack.push(s[i])
    } else {  //当前获取到的是右边的括号  //考虑右边括号多，没有左边的括号配对
      if (!stack.length || lToR[stack.pop()] !== s[i]) {     // '{' === '}'
        return false
      }
    }
  }

  return !stack.length  //考虑左边括号多了
};

console.log(isValid(s));

